{!! Html::style(env("APP_URL").'/assets/backend/libs/datepicker/bootstrap-datetimepicker.min.css') !!}

<div class="tabs-container">

    <div class="tab-content">
        <div id="tab-1" class="tab-pane active">

            {!! Form::open( [ 'route' => ['admin.shop.take.stock.index'], 'method' => 'get', 'id' => 'base-form','class'=>'form-horizontal'] ) !!}
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-2">
                        <a class="btn btn-primary" href="{{ route('admin.shop.take.stock.plan.create') }}" no-pjax>新增盘点计划</a>
                    </div>

                </div>

                {!! Form::close() !!}

                <br>

                <div class="table-responsive">
                    @if($lists && $lists->count()>0)
                        <table class="table table-hover table-striped">
                            <tbody>
                            <!--tr-th start-->
                            <tr>
                                <th>计划名称</th>
                                <th>创建时间</th>
                              {{--  <th>盘点条件</th>
                                <th>计划商品(件)</th>--}}
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            <!--tr-th end-->
                            @foreach ($lists as $item)
                                <tr>
                                    <td>{{$item->name}}</td>
                                    <td>{{$item->created_at}}</td>
                                    {{--<td>{{$item->condition_text}}</td>--}}
                                    {{--<td>{{$item->items->count()}}
                                        @if($item->status==0)
                                            <a href="javascript:;" class="btn btn-xs btn-primary"
                                               data-toggle="modal-plan-items"
                                               data-target="#modal" data-backdrop="static" data-keyboard="false"
                                               data-url="{{route('admin.shop.take.stock.plan.storeItemsModal',['plan_id'=>$item->id])}}">
                                                执行导入盘点商品
                                            </a>
                                        @endif
                                    </td>--}}
                                    <td>{{$item->status_text}}</td>
                                    <td>
                                        @if($item->status==0)
                                           {{-- <a href="{{ route('admin.shop.take.stock.create',['plan_id'=>$item->id]) }}"
                                               class="btn btn-xs btn-success">
                                                <i class="fa fa-pencil-square-o" data-toggle="tooltip"
                                                   data-placement="top"
                                                   title="操作盘点"></i>
                                            </a>--}}

                                            <a href="javascript:;"
                                               data-href="{{ route('admin.shop.take.stock.plan.changeStatus',['plan_id'=>$item->id]) }}"
                                               data-type="completed"
                                               class="btn btn-xs btn-success change-plan">
                                                <i class="fa fa-pencil" data-toggle="tooltip"
                                                   data-placement="top"
                                                   title="标记为已盘点"></i>
                                            </a>
                                        @endif
                                        <a href="{{ route('admin.shop.take.stock.plan.show',['plan_id'=>$item->id]) }}"
                                           class="btn btn-xs btn-success">
                                            <i class="fa fa-eye" data-toggle="tooltip"
                                               data-placement="top"
                                               title="查看盘点数据"></i>
                                        </a>
                                        @if($item->can_cancel)
                                            <a href="javascript:;" data-type="cancel"
                                               data-href="{{route('admin.shop.take.stock.plan.changeStatus',['plan_id'=>$item->id])}}"
                                               class="btn btn-xs btn-danger change-plan"><i class="fa fa-times"
                                                                                            data-toggle="tooltip"
                                                                                            data-placement="top"
                                                                                            title=""
                                                                                            data-original-title="作废计划"></i></a>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="6" class="footable-visible">
                                    {!! $lists->render() !!}
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    @else
                        <div>
                            &nbsp;&nbsp;&nbsp;当前无数据
                        </div>
                    @endif
                </div><!-- /.box-body -->
            </div>
        </div>
    </div>
</div>

<div id="modal" class="modal inmodal fade" data-keyboard=false data-backdrop="static"></div>

<script>
    $(document).on('click.modal.data-api', '[data-toggle="modal-plan-items"]', function (e) {
        var $this = $(this);
        modalUrl = $this.data('url');
        if (modalUrl) {

            var $target = $($this.attr('data-target'));
            $target.modal('show');
            $target.html('').load(modalUrl, function () {

            });
        }
    });

    $(function () {
        $('.change-plan').on('click', function () {
            var OpUrl = $(this).data('href');
            var OpType = $(this).data('type');
            var text = '确认取消该盘点计划吗';

            if (OpType == 'completed') {
                text = '确认标记该盘点计划为已完成吗';
            }


            swal({
                        title: text,
                        text: '',
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确认",
                        cancelButtonText: "取消",
                        closeOnConfirm: false
                    },
                    function () {
                        $.post(OpUrl, {token: _token, type: OpType}, function (result) {
                            if (result.status) {
                                swal({
                                            title: "操作成功",
                                            text: "",
                                            type: "success"
                                        },
                                        function () {
                                            location.reload();
                                        });
                            } else {
                                swal('操作失败', '', 'error');
                            }
                        });
                    });
        });
    });

</script>